public class Main {
    public static void main(String[] args) {
        Solution s = new Solution();

    }
}


class Solution {
    public boolean isValidSudoku(char[][] board) {
        return isRowsColsValid(board) && isBoxValid(board);
    }


    boolean isRowsColsValid(char[][] board){

        for(int i = 0; i < 9; i++){
            int[] rowNumCounts = new int[10];
            int[] colNumCounts = new int[10];
            for(int j = 0; j < 9; j++){
                int rowNum = parseInt(board[i][j]);
                int colNum = parseInt(board[j][i]);
                if(rowNum != 0){
                    rowNumCounts[rowNum]++;
                }
                if(colNum != 0){
                    colNumCounts[colNum]++;
                }

                if(rowNumCounts[rowNum] > 1 || colNumCounts[colNum] > 1){
                    return false;
                }
            }
        }
        return true;
    }

    boolean isBoxValid(char[][] board){
        for(int i = 0; i < 9; i += 3){
            for(int j = 0; j < 9; j += 3){
                int[] numCounts = new int[10];

                for(int m = i; m < i + 3; m++){
                    for(int n = j; n < j + 3; n++){
                        int num = parseInt(board[m][n]);
                        if(num != 0){
                            numCounts[num]++;
                            if(numCounts[num] > 1){
                                return false;
                            }
                        }
                    }
                }
            }
        }
        return true;
    }

    int parseInt(char c){
        if(c == '.'){
            return 0;
        }
        return c - '0';
    }
}